import { defineStore } from "pinia";
import { ref } from 'vue';


export const useSystemStore = defineStore('system', () => {

  const sysInfo = ref<UniApp.GetSystemInfoResult>();  // 系统信息
  // #ifdef MP-WEIXIN
  const menuinfo = ref<UniApp.GetMenuButtonBoundingClientRectRes>(); // 微信胶囊信息
  // #endif
  const customHeight = ref<number>(0); // 自定义高度
  const customWidth = ref<string>("100%"); // 自定义宽度
  const navHeight = ref<number>(0); // 导航栏总高度
  const statsuHeight = ref<number>(0); // 手机状态栏高度

  const getSysInfo = () => {
    sysInfo.value = uni.getSystemInfoSync();
    console.log(sysInfo.value);

    statsuHeight.value = sysInfo.value.statusBarHeight || 0; // 手机状态栏高度

    // #ifdef MP-WEIXIN
    menuinfo.value = uni.getMenuButtonBoundingClientRect();
    customHeight.value = menuinfo.value.height + 2 * (menuinfo.value.top - statsuHeight.value);
    customWidth.value = `calc(100% - ${menuinfo.value.width + sysInfo.value.windowWidth - menuinfo.value.right}px)`
    console.log(customWidth.value);
    // #endif

    // #ifdef APP-PLUS
    customHeight.value = 50;
    // #endif

    // #ifdef H5
    customHeight.value = 44;
    // #endif

    navHeight.value = customHeight.value + statsuHeight.value;

    // console.log(sysInfo.value);
    // console.log(menuinfo.value);
  }

  return {
    sysInfo,
    // #ifdef MP-WEIXIN
    menuinfo,
    // #endif
    customHeight,
    customWidth,
    navHeight,
    statsuHeight,
    getSysInfo
  }
})
